home *** CD-ROM | disk | FTP | other *** search
- Path: Rezonet.net!news
- From: ray@ultimate-tech.com (Ray Dunn)
- Newsgroups: comp.lang.c
- Subject: Re: quick decision: is n a power of 2?
- Date: 25 Jan 1996 03:02:24 GMT
- Organization: Ultimate Technographics Inc.
- Message-ID: <4e6rs0$dvl@ns.RezoNet.NET>
- References: <Pine.OSF.3.91.960119114608.18779E-100000@io.UWinnipeg.ca> <TANMOY.96Jan21104404@qcd.lanl.gov>
- NNTP-Posting-Host: 204.19.230.7
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.7
-
- In referenced article, Tanmoy Bhattacharya says...
- >Consider x = 0...0101. -x = 1...1011
- >-x & x == 1. So I cannot quite figure out what was meant above.
- >
- >x && !(x & ~-x) is a possible solution: But since ~-x is the same as
- >(x-1), this is the same as an already posted answer. (I am sorry that
- >in my hurry I missed the x && bit in a previous post).
- >
- >Instead of calling for 2's complement arithmetic, I prefer to say that
- >these should only be used for unsigned types.
-
- I don't undersand this last comment. None of the examples you show
- work except in two's complement arithmetic.
-
- --
- Ray Dunn (opinions are my own) | Phone: (514) 938 9050
- Montreal | Phax : (514) 938 5225
- ray@ultimate-tech.com | Home : (514) 630 3749
-
-